package risk.control.application.utils;

import android.content.Context;
import android.os.Build;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;

import risk.control.application.utils.mmkv.MMKVUtils;
import risk.control.application.utils.mmkv.MMKV_KEY;


public class DeviceUtils {

    private static String appVersion;
    private static String osVersion;
    private static String apiLevel;
    private static String screenWidth;
    private static String screenHeight;
    private static String manufacturer;
    private static String deviceUniqueId;

    public static void init(Context context) {
        try {
            //程序版本
            appVersion = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
            //获取操作系统版本名称
            osVersion = Build.VERSION.RELEASE;
            //获取API级别
            apiLevel = String.valueOf(Build.VERSION.SDK_INT);
            //屏幕宽高
            WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
            Display display = windowManager.getDefaultDisplay();
            DisplayMetrics displayMetrics = new DisplayMetrics();
            display.getMetrics(displayMetrics);
            int width = displayMetrics.widthPixels;
            int height = displayMetrics.heightPixels;
            screenWidth = String.valueOf(width);
            screenHeight = String.valueOf(height);
            //厂商标识
            manufacturer = Build.BRAND + "-" + Build.MODEL;
            //设备唯一ID
            String id = MMKVUtils.getString(MMKV_KEY.DEVICE_UNIQUE_ID);
            if (id == null || id.isEmpty()) {
                //重新生成
                deviceUniqueId = EquipmentIdUtils.generateEquipmentId();
            } else {
                deviceUniqueId = id;
            }
        } catch (Exception e) {
            LogUtils.e(e.getMessage());
        }
    }

    public static String getAppVersion() {
        return appVersion;
    }

    public static String getOsVersion() {
        return osVersion;
    }

    public static String getApiLevel() {
        return apiLevel;
    }

    public static String getScreenWidth() {
        return screenWidth;
    }

    public static String getScreenHeight() {
        return screenHeight;
    }

    public static String getManufacturer() {
        return manufacturer;
    }

    public static String getDeviceUniqueId() {
        return deviceUniqueId;
    }
}
